<template>
  <div class="technicDetail">
    <van-nav-bar @click-left="$router.back()" class="login_head">
      <template #left>
        <span class="iconfont arrowleft">&#xe637;</span>
      </template>
    </van-nav-bar>
    <div class="head">
      <h3>{{ myarticle.title }}</h3>
      <div class="info">
        <span class="time">{{ myarticle.created_at | formatTime }}</span>
        <span><van-icon name="eye-o" /> {{ myarticle.read }}</span>
        <span @click="zan">
          <van-icon name="good-job-o" :class="iszan ? '' : 'red'" />
          {{ zannum }}</span
        >
      </div>
    </div>
    <div class="content" v-html="myarticle.content"></div>
  </div>
</template>

<script>
import { articlesTechnicDetail, starArticle } from '@/api/api.js'
export default {
  data () {
    return {
      id: '',
      myarticle: {},
      zannum: '',
      iszan: false
    }
  },
  created () {
    this.id = this.$route.params.id
    this.getArt()
    if (this.zannum === 0) {
      this.iszan = false
    }
  },

  methods: {
    // 点赞
    async zan () {
      this.iszan = !this.iszan
      const res = await starArticle({ article: this.id })
      this.zannum = res.data.data.num
    },
    async getArt () {
      const res = await articlesTechnicDetail(this.id)
      this.myarticle = res.data.data
      this.zannum = this.myarticle.star
    }
  }
}
</script>

<style lang="less" scoped>
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.technicDetail {
  padding: 10px;
  .arrowleft {
    font-size: 50px;
    margin-left: -20px;
  }
  .head {
    margin-top: 10px;
    h3 {
      font-weight: normal;
      font-size: 16px;
      padding-right: 26px;
      margin-left: 7px;
    }
    .info {
      margin-bottom: 30px;
      span {
        font-size: 12px;
        color: #999;
        padding: 0 10px;
      }
      .time {
        margin-right: 24px;
      }
      line-height: 30px;
      h3 {
        font-weight: normal;
        font-size: 16px;
        padding-right: 26px;
        margin-left: 7px;
      }
      span {
        font-size: 12px;
        color: #999;
        padding: 0 10px;
      }
      .time {
        margin-right: 24px;
      }
    }
  }
  .content {
    font-size: 16px;
    /deep/img {
      width: 100% !important;
    }
  }
  .red {
    color: red;
  }
}
</style>
